class MyPromise {
    constructor(fun) {
        //三种状态 pending filfilled rejected
        this.status = 'pending';
        //成功的数据
        this.value = '';//成功的数据
        this.error = '';//失败的信息

        //成功触发
        let resolve = (data) => {
            this.status = 'filfilled';
            this.value = data
        }
        //失败触发
        let reject = (error) => {
            this.status = 'rejected';
            this.error=error
        }

        fun(resolve, reject)

    }
    then(successfun,rejectfun){
        if(this.status === 'fulfilled'){
            successfun()
        }else if(this.status === 'rejected'){ 
            rejectfun()
        }
    }
}
new MyPromise((resolve, reject) => {
    console.log('success')
}).then(res => {
    //成功的状态
    console.log(res)
}, error => {
    //失败的状态
    console.log(error)
})